package com.handpay.zztong.hp.setting.activity;

import android.app.Activity;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.widget.TextView;

import com.handpay.framework.ClientEngine;
import com.handpay.framework.HttpEngine;
import com.handpay.framework.LuaTableUtil;
import com.handpay.zztong.hp.R;
import com.handpay.zztong.hp.base.activity.ZZTongActivity;
import com.handpay.zztong.hp.bean.ActionBar;
import com.handpay.zztong.hp.config.ZZTConfig;
import com.handpay.zztong.hp.log.HPLog;
import com.handpay.zztong.hp.setting.model.versioninfo.VersionInfoBean;

import java.util.Hashtable;

import se.krka.kahlua.vm.LuaTable;

public class VersionIntroductionActivity extends ZZTongActivity {
    private TextView versionDescription, versionNumber;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_version_introduction);
        super.onCreate(savedInstanceState);
        versionDescription = (TextView) findViewById(R.id.version_description);
        versionNumber = (TextView) findViewById(R.id.version_number);
        VersionInfoBean versionInfoBean = getIntent().getParcelableExtra("versionInfoBean");
        if (versionInfoBean != null) {
            versionNumber.setText(String.format("%s%s", getString(R.string.current_version_number), versionInfoBean.getVersion()));
            String description = versionInfoBean.getDescription().replace("&", "\n");
            versionDescription.setText(String.format("%s%s", getString(R.string.update_context), description));
        }
    }

    @Override
    public ActionBar getActivityActionBar() {
        //leftBar goBack();
        return new ActionBar(this.getString(R.string.about_instruction), true);
    }

    @Override
    protected boolean isShownTabs() {
        return false;
    }

    @Override
    protected void onResume() {
        super.onResume();
//        doVersionDesc();
    }

//    public void doVersionDesc() {
//        Hashtable<String, String> params = new Hashtable<String, String>();
//        params.put("version", ClientEngine.VERSION);
//        params.put("platform", ClientEngine.MOBILETYPE);
//        params.put("channel", ZZTConfig.UPDATE_CHANNEL);
//        doJsonPost(this, Do_ZztVersionDesc, VersionInfoBean.class, params);
//    }

//    @Override
//    public boolean netResponse(String action, Hashtable<String, Object> resp,
//                               boolean showAlert, OnClickListener on) {

//		if (action.equals(Do_ZztNewVerifyVersion)) {
//			doVersionDesc();
//		} else{
//
//		}
//        boolean result = super.netResponse(action, resp, showAlert, on);
//        if (result == true) {
//            this.setResult(Activity.RESULT_CANCELED);
//            this.closeProgressDialog();
//            return true;
//        }
//        byte data[] = (byte[]) resp.get(HttpEngine.Key_RespData);
//        LuaTable luaTable = LuaTableUtil.stringToLuaTable(data, isDataCompile);
//        String description = (String) luaTable.rawget("description");
//        String versions = (String) luaTable.rawget("version");
//        try {
//            description = description.replace("&", "\n");
//            HPLog.e("jjyang", "version---" + versions);
//            versionNumber.setText(getString(R.string.current_version_number) + versions);
//            versionDescription.setText(getString(R.string.update_context) + description);
//        } catch (Exception e) {
//            e.printStackTrace();
//            HPLog.i("result", e.toString());
//        }
//        return true;
//    }

}
